//============================================================================
// Name        : hello.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<iostream>
#include<exception>
#include<string>
#include <stdio.h>
//#include "CloudClient.h"
//#include "ExceptionHandler.h"
//#include "DBHelper.h";
//#include "CommonUtilities.h"
#include "SocketClient.h";

using namespace std;
//using namespace database;
//using namespace sql;
//using namespace utilities;
using namespace networklib;



//int main() {
	//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
/*
	SocketClient* client = new SocketClient("localhost", "6001");
	if (!client->connected) {
		cout<<"Failed to connect to edge server"<<endl;
	} else {
		cout<<"connected"<<endl;
	}
*/
/*
	time_t t = 1329128554;
	cout<<"t = "<<t<<endl;
	CommonUtilities* ut = new CommonUtilities();
	char s[22];
	ut->getTimeString(t, s, 22);
	cout<<"s = "<<s<<endl;

	char* o = "2012-02-13 02:22:34";
	cout<<"o = "<<o<<endl;
	time_t ot = ut->getTimeFromString(o);
	cout<<"ot = "<<ot<<endl;
*/

/*
	DBHelper* db = new DBHelper();
	ResultSet* req = db->checkRequest(1, "hdfstest2.pdf");
	//while(req->next());

	DBHelper* db1 = new DBHelper();
	ResultSet* res = db1->getEdgeServerGroup();

	if(res->first())
		cout<<"EdgeServerGroupID = "<<res->getInt("EdgeServerGroupID");
	else
		cout<<"false"<<endl;
*/

	/*
	cout<<"Helper class starts here"<<endl;

	CloudClient* client = new CloudClient("localhost", 54310);

	client->writeFileToHDFS("/home/hduser/testfiles/test2.pdf","hdfstest2.pdf");
	cout<<"File Write Completed"<<endl;

	client->getFileFromHDFS("hdfstest2.pdf","/home/hduser/testfiles/hdfstest2.pdf");
	cout<<"File Read Complete"<<endl;
	client->cloudConn->Close();

	cout<<"Complete"<<endl;
	 */

/*
	try {

			cout<<"test exception"<<endl;
			//int i = 1;
			//int j = 0;
			//int k = i/j;

			//char* s = "a";
			//char c = s[2];

			int x = 0;
			if (x!=0)
				cout << "test";
			else
				throw(x);

		} catch (...) {
			cout<<"caught exception"<<endl;
			ExceptionHandler::processException("main()", "test");
		}
*/

/*
	char* fullFilePath; // = (char*)malloc(1000);
	int VendorID = 1234;
	size_t chunkIndex = 1234567891234;
	char* s = "/user/hduser/test2.pdf";
	//sprintf(fullFilePath, "/%d%s_%zu",VendorID, s, chunkIndex);
	sprintf(fullFilePath, "%zu", chunkIndex);

	cout << fullFilePath << endl;
	return 0;
*/
/*
	  time_t rawtime;
	  struct tm * timeinfo;
	  char buffer [22];

	  time ( &rawtime );
	  timeinfo = localtime ( &rawtime );

	  strftime (buffer,22,"%Y-%m-%d %I:%M:%S",timeinfo);
	  printf("%s",buffer);

	  return 0;
	  */

/*
	char* buff = "2012-02-13 02:22:34";
	cout<<buff<<endl;
	int yy, mm, dd, hour, min, sec;
	struct tm when;
	time_t tme;

	sscanf(buff, "%d-%d-%d %d:%d:%d", &yy, &mm, &dd, &hour, &min, &sec);

	//cout<<yy<<"-"<<mm<<"-"<<dd<<endl;

	if( yy < 70 ) yy+= 100; // year 2000 compliant
	time(&tme);
	//cout<<tme<<endl;
	when = *localtime(&tme);
	//cout<<when.tm_year<<endl;
	when.tm_year = yy - 1900;
	//cout<<when.tm_year<<endl;
	when.tm_mon = mm-1; when.tm_mday = dd;
	when.tm_hour = hour; when.tm_min = min; when.tm_sec = sec;
	time_t rawtime = mktime(&when);
	cout<< rawtime <<endl;

	struct tm * timeinfo;
	char buffer [22];

	//time ( &rawtime );
	timeinfo = localtime ( &rawtime );
	//time_t t = 1329128554;
	//timeinfo = localtime ( &t );

	strftime (buffer,22,"%Y-%m-%d %I:%M:%S",timeinfo);
	printf("%s",buffer);
*/
//}

